//
//  LFStatus.swift
//  SDAutoWeibo
//
//  Created by 刘健 on 16/3/24.
//  Copyright © 2016年 Clemmie. All rights reserved.
//

import UIKit

class LFStatus: NSObject {
      //MARK: -- tableView高度优化
    var rowHight: CGFloat?
    
    // 微博创建时间
    var created_at: String?
    
    // 微博ID
    var id: Int64 = 0
    
    // 微博信息内容
    var text: String?
    
    // 微博来源
    var source: String? {
        didSet {
            
            source = source?.rangeString()
        }
    }
    
    // 微博配图
    var pic_urls: [[String: AnyObject]]? {
        didSet {
            //添加属性 一定要创建数组
            thumbnailPicURLs = [NSURL]()
            if pic_urls?.count > 0 {

                for dict  in pic_urls! {
                    if let urlString = dict["thumbnail_pic"] as? String {
                        if let url = NSURL(string: urlString) {
                            thumbnailPicURLs?.append(url)
                        }
                    }
                }
            }
            
        }
    }
   
    //保存微博照片的URL数组
    var thumbnailPicURLs: [NSURL]?
    
    // 转发数
    var reposts_count: Int = 0
    
    // 评论数
    var comments_count: Int = 0
    
    // 表态数
    var attitudes_count: Int = 0
    
    //用户信息
    var user: LFUser?
    
    /// 被转发的微博
    var retweeted_status: LFStatus?
    
    // 初始化字典转模型
    init(dict:[String : AnyObject]?) {
        super.init()
        setValuesForKeysWithDictionary(dict!)
    }
    
    //拦截key，寻找想要的key，给LFuser 赋值
    override func setValue(value: AnyObject?, forKey key: String) {
        
        //获取用户信息
        if   key == "user" {
            
            //不推荐强制拆包
            if let dict = value as? [String :AnyObject] {
                user = LFUser(dict: dict)
            }
            return
        }
        
        //获取转发微博
        if key == "retweeted_status" {
            if let dict = value as? [String :AnyObject] {
                retweeted_status = LFStatus(dict: dict)
            }
            return
        }
        //在后面调用父类，防止2次赋值，被父类重写
        super.setValue(value, forKey: key)
    }
    
    
    
    //过滤不需要的key
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}